{extend name="public/base"}
{block name="title"}{$site_title}{/block}
{block name="content"}
<div class="main-wrap">

    <div class="crumb-wrap">
        <div class="crumb-list">
            <i class="icon-font"></i>
            <a href="javascript:void (0)" onclick="site()">首页</a>
            <span class="crumb-step">&gt;</span>
            <a class="crumb-name" href="/baibu/admin/Product/">产品管理</a>
            <span class="crumb-step">&gt;</span>
            <span class="crumb-name">分类列表</span>
        </div>
    </div>
    <div class="result-wrap">
        <form name="myform" id="myform">
            <div class="result-title">
                <div class="result-list">
                    <a href="/baibu/admin/Product/add">
                        <i class="icon-font">&#xe005;</i>发布产品
                    </a>
                    <a href="/baibu/admin/Product/category">
                        <i class="icon-font">&#xe041;</i>分类列表
                    </a>
                    <a href="/baibu/admin/Product/categoryAdd">
                        <i class="icon-font"></i>添加分类
                    </a>
                    <a id="batchDel" href="javascript:void(0)">
                        <i class="icon-font"></i>批量删除
                    </a>
                </div>
            </div>
            <div class="result-content">
                <table class="result-tab tc" width="100%" num="{$cate|count}">
                    <tr>
                        <th class="tc" width="5%" align="center">
                            <input class="allChoose" type="checkbox" >
                        </th>
                        <th class="tc">ID</th>
                        <th class="tc">分类名称</th>
                        <th class="tc">上级分类</th>
                        <th class="tc">说明</th>
                        <th class="tc">状态</th>
                        <th class="tc">操作</th>
                    </tr>
                    {volist name="cate" id="vo"}
                    <tr class="tr{$vo.cate_id}">
                    <td class="tc">
                    <input name="cate_id[]" value="{$vo.cate_id}" type="checkbox">
                    </td>
                    <td>{$vo.cate_id}</td>
                    <td>{$vo.cate_name}</td>
                    <td>{$vo.cate_pid}</td>
                    <td>{$vo.cate_remark}</td>
                    <td>
                    {if $vo.cate_status == 1}

                    <img class="img{$vo.cate_id}" name="cate_id={$vo.cate_id}&cate_status=0" style="cursor:pointer" src="_IMAGE_/default/dui.png">
                    {else /}
                    <img class="img{$vo.cate_id}" name="cate_id={$vo.cate_id}&cate_status=1" style="cursor:pointer" src="_IMAGE_/default/cuo.png">
                    {/if}
                    </td>
                        <td>
                            <a class="link-update" href="{:url('http://'.$_SERVER['HTTP_HOST'].'/baibu/admin/Product/categoryEdit', ['cate_id' => $vo.cate_id])}">修改</a>
                            <a class="link-del" title="{$vo.cate_id}" href="javascript:">删除</a>
                        </td>
                    </tr>
                    {/volist}
                </table>
                <div class="list-page" style="margin:0 auto;">
                    {$page}
                </div>
            </div>
        </form>
    </div>
</div>
{/block}
{block name="js"}
<script>
    $(function () {
        console.log("%cHello","color:red");
        $('.allChoose').click(function () {
            if (this.checked) {
                $("input[name=cate_id\\[\\]]").prop("checked",true);
            }else{
                $("input[name=cate_id\\[\\]]").prop("checked",false);
            }
        });
        $('input[name=cate_id\\[\\]]').click(function () {
            if(this.checked){
                $(this).prop('checked',true);
                getNum();
            } else{
                $(this).prop('checked',false);
                getNum();
            }
        });
        function getNum(){
            var num = 0;
            $('input[name=cate_id\\[\\]]').each(function (i,item) {
                if(item.checked){
                    num += 1;
                }else{
                    num -= 1;
                }
            });
            var total = $('table').attr('num');
            if(num == total){
                $('.allChoose').prop('checked',true);
            }else {
                $('.allChoose').prop('checked', false);
            }
        }
        $('#batchDel').click(function () {
            if(!$('input[name=cate_id\\[\\]]').is(':checked')){
                layer.msg('请勾选要删除的分类',{icon:0,time:1100});
                return;
            }
            $.ajax({
                url : '/baibu/admin/Product/categoryDel',
                dataType : 'json',
                type : 'get',
                data : $('form').serialize(),
                success : function (data) {
                    if(data.status == 1){
                        var id = data.data;
                        $.each(id,function (i,item) {
                            var tr = '.tr'+item;
                            $(tr).hide();
                        });
                        layer.msg(data.msg,{icon:1,time:1000});
                    }else{
                        layer.msg(data.msg,{icon:5,time:1000});
                    }
                }
            });
        });
        $('.link-del').click(function () {
            var mid = $(this).prop('title');
            if(!mid){
                layer.msg('参数错误!',{icon:5,time:1200});
                return;
            }
            $.ajax({
                url : '/baibu/admin/Product/categoryDel',
                dataType : 'json',
                type : 'get',
                data : {cate_id:mid},
                success : function (data) {
                    if(data.status == 1){
                        var id = data.data;
                        var tr = '.tr'+id;
                        $(tr).hide();
                        layer.msg(data.msg,{icon:1,time:1200});
                    }else{
                        layer.msg(data.msg,{icon:5,time:1200});
                    }
                }
            });
        });
        $('img').click(function () {
            var info = $(this).prop('name');
            var c = '.'+$(this).prop('class');
            if(!info){
                layer.msg('参数错误!',{icon:0,time:1200});
                return;
            }
            $.ajax({
                url : '/baibu/admin/Product/categoryStatus',
                dataType : 'json',
                type : 'get',
                data : info,
                success : function (data) {
                    if(data.status){
                        $(c).prop('src',data.data.img);
                        $(c).prop('name',data.data.name);
                        layer.msg(data.msg,{icon:1,time:1200});
                    }else{
                        layer.msg(data.msg,{icon:2,time:1200});
                    }
                }
            });
        });
    });
</script>
{/block}